// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var tools = require("tools");
	var dialog = require("dialog");
	var validate = require("validate");
	var css_detail_info = require("./exceptionManage.css");
	var databind = require("databind");
	var constant = require("constant");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var oData = {
		pageIndex: pageIndex,
		pageSize: pageSize,
		totalPageCount: totalPageCount,
		totalRecordCount: totalRecordCount,
		handleState : ""
	};
	var init = function() {
		inquireAbnormalPageList(oData);
		initEvent();
		router.init();
		databind.fillInput($("#exceptionManage"), {
			action: "personalWorkbench.json",
			async: true
		});
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}

		$(".handleState1").unbind("click").click(function() {
			$(".page").addClass("none");
			$("#exceptionManage").css("display", "block");
			oData = {
				pageIndex: pageIndex,
				pageSize: pageSize,
				totalPageCount: totalPageCount,
				totalRecordCount: totalRecordCount
			};
			oData.handleState = 1;
			$("#exceptionManage .handleState").val(1);
			inquireAbnormalPageList(oData);
		});
		$(".handleState2").unbind("click").click(function() {
			$(".page").addClass("none");
			$("#exceptionManage").css("display", "block");
			oData = {
				pageIndex: pageIndex,
				pageSize: pageSize,
				totalPageCount: totalPageCount,
				totalRecordCount: totalRecordCount
			};
			oData.handleState = 2;
			$("#exceptionManage .handleState").val(2);
			inquireAbnormalPageList(oData);
		});
		$(".handleState3").unbind("click").click(function() {
			$(".page").addClass("none");
			$("#exceptionManage").css("display", "block");
			oData = {
				pageIndex: pageIndex,
				pageSize: pageSize,
				totalPageCount: totalPageCount,
				totalRecordCount: totalRecordCount
			};
			oData.handleState = 3;
			$("#exceptionManage .handleState").val(3);
			inquireAbnormalPageList(oData);
		});
		$(".handleState4").unbind("click").click(function() {
			$(".page").addClass("none");
			$("#exceptionManage").css("display", "block");
			oData = {
				pageIndex: pageIndex,
				pageSize: pageSize,
				totalPageCount: totalPageCount,
				totalRecordCount: totalRecordCount
			};
			oData.handleState = 4;
			$("#exceptionManage .handleState").val(4);
			inquireAbnormalPageList(oData);
		});

		//左侧菜单栏 延期计息
		$(".interestDelayA").unbind("click").click(function() {
			router.route("main/interestDelayList.html?left=12&lm=7&tm=5");
		});

		//左侧菜单栏 延期还款
		$(".pickupDelayA").unbind("click").click(function() {
			router.route("main/pickupDelayList.html?left=11&lm=7&tm=5");
		});

		//左侧菜单栏 提前还款
		$(".pickupPreA").unbind("click").click(function() {
			router.route("main/pickupPreList.html?left=10&lm=7&tm=5");
		});

		//左侧菜单栏 赎货申请
		$(".pickupRansomA").unbind("click").click(function() {
			router.route("main/pickupRansomList.html?left=14&lm=7&tm=5");
		});

		//左侧菜单栏 扣货申请
		$(".detainedA").unbind("click").click(function() {
			router.route("main/detainedList.html?left=13&lm=7&tm=5");
		});

		//左侧菜单栏 处置
		$(".badassetsHandleA").unbind("click").click(function() {
			router.route("main/badassetsHandleList.html?left=15&lm=7&tm=5");
		});

		$("#exceptionWrapper").on("click", "#exceptionManangeSearch", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化	
			oData = {
				pageIndex: pageIndex,
				pageSize: pageSize,
				totalPageCount: totalPageCount,
				totalRecordCount: totalRecordCount,
				handleState: $("#exceptionManage .handleState").val(),
				financeNumber: $("#exceptionManage .financeNumber").val(),
				endDate: $("#exceptionManage .endDate").val(),
				startDate: $("#exceptionManage .startDate").val(),
				abnormalState: $("#exceptionManage .abnormalState").val()
			};
			inquireAbnormalPageList(oData);
		});
	};


	//查询异常信息列表
	var inquireAbnormalPageList = function(oData) {
		tools.loadList("inquireAbnormalPageList.json", $("#expectionListBody"), $("#expectionListTpl"), oData, function() {
			$(".exceptionDetail").unbind("click").click(function() {
				router.route("exception/exceptionDetailInfo.html?abnormalId=" + $(this).parents("tr").attr("abnormalId"));
			});
		});
	};

	return {
		init: init
	};
});